﻿Imports DVBViewerServer
Imports DvbViewerSignalMonitor

Public Class Get_DVB_Infos

    Private DVBViewer As DVBViewerServer.DVBViewer
    Private _dvb_DataTable As Data.DataTable
    Private _ComServerNoAvabile As Boolean = False

    Private _HardWare_OK As Boolean = False
    ReadOnly Property HardWareOK() As Boolean
        Get
            Return _HardWare_OK
        End Get
    End Property


    Private _iDVB_Hardware_Count As Integer
    ReadOnly Property DVB_HardwareCount() As Integer
        Get
            Return _iDVB_Hardware_Count
        End Get
    End Property


    Private _DVB_Sender As String
    ReadOnly Property DVB_Sender() As String
        Get
            Return _DVB_Sender
        End Get
    End Property

    Private _ErrorMessage As String = String.Empty
    ReadOnly Property ErrorMessage() As String
        Get
            Return _ErrorMessage
        End Get
    End Property

   
  
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dvb_DataTable"></param>
    ''' <remarks></remarks>
    Sub New(dvb_DataTable As Data.DataTable)
        _dvb_DataTable = dvb_DataTable
        _HardWare_OK = Init_ComServer(_dvb_DataTable)
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dvb_DataTable"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function Init_ComServer(dvb_DataTable As Data.DataTable) As Boolean
        Try

            Dim newTuner As Boolean

            DVBViewer = GetObject(, "DVBViewerServer.DVBViewer")
            _iDVB_Hardware_Count = DVBViewer.DVBHardware.CardCount


            If dvb_DataTable.Rows.Count <> _iDVB_Hardware_Count Then
                dvb_DataTable.Rows.Clear()
                For i = 0 To _iDVB_Hardware_Count - 1
                    dvb_DataTable.Rows.Add()
                Next
                newTuner = True
            End If

            If _iDVB_Hardware_Count > 0 Then
                For i = 0 To _iDVB_Hardware_Count - 1

                    If newTuner Then
                        dvb_DataTable.Rows(i).Item(0) = DVBViewer.DVBHardware.HardwareName(i)
                    End If

                    dvb_DataTable.Rows(i).Item(1) = DVBViewer.DVBHardware.SignalQuality(i)
                    dvb_DataTable.Rows(i).Item(2) = DVBViewer.DVBHardware.SignalStrength(i)
                    dvb_DataTable.Rows(i).Item(3) = DVBViewer.DVBHardware.SignalErrorRate(i)

                Next

                _DVB_Sender = "Active Kanal: " & DVBViewer.CurrentChannelNr.ToString & " - " & DVBViewer.CurrentChannel.Name
                _HardWare_OK = True
            Else
                _HardWare_OK = False
            End If

            Return True
        Catch ex As Exception
            _ErrorMessage = ex.Message
            _iDVB_Hardware_Count = 0
            _HardWare_OK = False
            Return False
        End Try
    End Function
End Class
